package com.four.reimbursemanage.service.impl;

import com.four.reimbursemanage.common.bean.Page;
import com.four.reimbursemanage.dao.PayapplyMapper;
import com.four.reimbursemanage.entity.Dailyapply;
import com.four.reimbursemanage.entity.Payapply;
import com.four.reimbursemanage.service.IPayapplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 支付申请Service业务层处理
 * 
 * @author lwy
 * @date 2024-09-13
 */
@Service
public class PayapplyServiceImpl implements IPayapplyService
{
    @Autowired
    private PayapplyMapper payapplyMapper;

    /**
     * 查询支付申请
     * 
     * @param id 支付申请主键
     * @return 支付申请
     */
    @Override
    public Payapply selectPayapplyById(Integer id)
    {
        return payapplyMapper.selectPayapplyById(id);
    }



    /**
     * 查询支付申请列表
     * @return 支付申请
     */
    @Override
    public Page<Payapply> getOnrePage(int pageNum, int pageSize, String applyDepartment, String transactor, String payee, String paymoney, String type, Date month, Integer state) {
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<Payapply> list=payapplyMapper.selectPayapplyList(start,pageSize, applyDepartment, transactor, payee, paymoney, type, month, state);
        //获取总条目数
        int total=payapplyMapper.countPayapply(applyDepartment, transactor, payee, paymoney, type, month, state);
        //计算总页数
        int pages =(int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<Payapply> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }

    @Override
    public Page<Payapply> getOnrePageUser(int pageNum, int pageSize, String applyDepartment, String transactor, String payee, String paymoney, String type, Date month, Integer state, String number) {
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<Payapply> list=payapplyMapper.selectByUser(start,pageSize, applyDepartment, transactor, payee, paymoney, type, month, state, number);
        //获取总条目数
        int total=payapplyMapper.countUser(applyDepartment, transactor, payee, paymoney, type, month, state, number);
        //计算总页数
        int pages =(int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<Payapply> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }


   /* @Override
    public List<Payapply> selectPayapplyList(Payapply payapply)
    {
        return payapplyMapper.selectPayapplyList(payapply);
    }*/

    /**
     * 新增支付申请
     * 
     * @param payapply 支付申请
     * @return 结果
     */
    @Override
    public boolean insertPayapply(Payapply payapply)
    {
        if (payapply == null){
            return false;
        }
        return payapplyMapper.insertPayapply(payapply)>0;
    }

    /**
     * 修改支付申请
     * 
     * @param payapply 支付申请
     * @return 结果
     */
    @Override
    public boolean updatePayapply(Payapply payapply)
    {
        if (payapply == null){
            return false;
        }
        return payapplyMapper.updatePayapply(payapply)>0;
    }

    /**
     * 批量删除支付申请
     * 
     * @param ids 需要删除的支付申请主键
     * @return 结果
     */
    @Override
    public int deletePayapplyByIds(Integer[] ids)
    {
        return payapplyMapper.deletePayapplyByIds(ids);
    }


    /*撤销*/
    @Override
    public boolean updateC(Payapply payapply) {
        if (payapply == null){
            return false;
        }
        payapply.setState(3);
        return payapplyMapper.updateStateById(payapply)>0;
    }

    /**
     * 删除支付申请信息
     * 
     * @param id 支付申请主键
     * @return 结果
     */
    @Override
    public int deletePayapplyById(Integer id)
    {
        return payapplyMapper.deletePayapplyById(id);
    }
}
